package shuzu;

import utils.Utils;

public class _02零所在的行列清零 {
    //将矩阵中0所在的行和列清零
    public static void main(String[] args) {
        int[][] matrix = {
                {1, 2, 3, 4, 100},
                {5, 6, 7, 0, 101},
                {9, 0, 11, 12, 102},
                {13, 14, 15, 16, 103},
                {104, 105, 106, 107, 103},
        };
        solve(matrix);
        Utils.printMatrix(matrix);
    }

    private static void solve(int[][] matrix) {
        int M = matrix.length;
        int N = matrix[0].length;
        int[] recordRow = new int[M];
        int[] recordCol = new int[N];
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                if (matrix[i][j] == 0) {
                    recordCol[i] = 1;
                    recordRow[j] = 1;
                }
            }
        }
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                if (recordCol[i] == 1 || recordRow[j] == 1) {
                    matrix[i][j] = 0;
                }
            }
        }
    }
}
